home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBASE102.ARJ / LSEQ.H < prev    next >
Text File  |  1991-09-23  |  5KB  |  157 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /*man---------------------------------------------------------------------------
  5. NAME
  6.      lseq - linked sequential file management library
  7.  
  8. SYNOPSIS
  9.      #include <lseq.h>
  10.  
  11. DESCRIPTION
  12.      The lseq library consists of a set of routines for the creation
  13.      and manipulation of doubly-linked sequential files.
  14.  
  15.      lseq uses the blkio library for file access and buffering.
  16.      Therefore bexit should be used in place of exit when using lseq.
  17.  
  18. SEE ALSO
  19.      lsclose, lscreate, lscursor, lsdelcur, lsfirst, lsgetcur,
  20.      lsgetlck, lsgetr, lsgetrf, lsinsert, lslast, lslock, lsnext,
  21.      lsopen, lsprev, lsputr, lsputrf, lsreccnt, lsrecsize, lssearch,
  22.      lssetbuf, lssetcur, lssetvbuf, lssync.
  23.  
  24. ------------------------------------------------------------------------------*/
  25. #ifndef H_LSEQ        /* prevent multiple includes */
  26. #define H_LSEQ
  27.  
  28. /* #ident    "@(#)lseq.h    1.5 - 91/09/23" */
  29.  
  30. #include <ansi.h>
  31.  
  32. /* ansi headers */
  33. #ifdef AC_STDDEF
  34. #include <stddef.h>
  35. #endif
  36.  
  37. /* library headers */
  38. #include <blkio.h>
  39.  
  40. /* constants */
  41. #define LSOPEN_MAX    BOPEN_MAX    /* max # lseqs open at once */
  42. #define LSBUFCNT    ((size_t)10)    /* default # of records to buffer */
  43.  
  44. /* macro to calculate buffer size needed by an lseq */
  45. #define LSBUFSIZ(RECSIZE, BUFCNT) ((size_t)(                \
  46.     sizeof(lshdr_t) +                        \
  47.     (BUFCNT) * (offsetof(lsrec_t, recbuf) + (RECSIZE)        \
  48. ))
  49.  
  50. /* type definitions */
  51. typedef bpos_t    lspos_t;    /* lseq position */
  52. #ifdef AC_PROTO
  53. typedef int (*lscmp_t)(const void *p1, const void *p2, size_t n);
  54. #else
  55. typedef int (*lscmp_t)();
  56. #endif
  57.  
  58. typedef struct {        /* lseq record */
  59.     lspos_t    next;        /* next record in list */
  60.     lspos_t    prev;        /* previous record in list */
  61.     void *    recbuf;        /* record contents */
  62. } lsrec_t;
  63.  
  64. typedef struct {        /* lseq file header */
  65.     bpos_t    flh;        /* position of free list head */
  66.     size_t    recsize;    /* record size */
  67.     int    flags;        /* flags */
  68.     lspos_t    first;        /* position of first record */
  69.     lspos_t    last;        /* position of last record */
  70.     unsigned long reccnt;    /* number records currently in lseq */
  71. } lshdr_t;
  72.  
  73. typedef struct {        /* lseq control structure */
  74.     lshdr_t    lshdr;        /* file header */
  75.     BLKFILE *bp;        /* block file */
  76.     int    flags;        /* status flags */
  77.     lspos_t    clspos;        /* current lseq position */
  78.     lsrec_t *clsrp;        /* current record */
  79. } lseq_t;
  80.  
  81. /* function declarations */
  82. #ifdef AC_PROTO
  83. int        lsclose(lseq_t *lsp);
  84. int        lscreate(const char *filename, size_t recsize);
  85. int        lsdelcur(lseq_t *lsp);
  86. int        lsfirst(lseq_t *lsp);
  87. int        lsgetcur(lseq_t *lsp, lspos_t *lsposp);
  88. int        lsgetlck(lseq_t *lsp);
  89. int        lsgetr(lseq_t *lsp, void *buf);
  90. int        lsgetrf(lseq_t *lsp, size_t offset, void *buf, size_t bufsize);
  91. int        lsinsert(lseq_t *lsp, const void *buf);
  92. int        lslast(lseq_t *lsp);
  93. int        lslock(lseq_t *lsp, int ltype);
  94. int        lsnext(lseq_t *lsp);
  95. lseq_t *    lsopen(const char *filename, const char *type);
  96. int        lsprev(lseq_t *lsp);
  97. int        lsputr(lseq_t *lsp, const void *buf);
  98. int        lsputrf(lseq_t *lsp, size_t offset, const void *buf,
  99.             size_t bufsize);
  100. int        lssearch(lseq_t *lsp, size_t offset, const void *buf,
  101.             size_t bufsize, lscmp_t cmp);
  102. int        lssetbuf(lseq_t *lsp, void *buf);
  103. int        lssetcur(lseq_t *lsp, const lspos_t *lsposp);
  104. int        lssetvbuf(lseq_t *lsp, void *buf, size_t bufcnt);
  105. int        lssync(lseq_t *lsp);
  106. #else
  107. int        lsclose();
  108. int        lscreate();
  109. int        lsdelcur();
  110. int        lsfirst();
  111. int        lsgetcur();
  112. int        lsgetlck();
  113. int        lsgetr();
  114. int        lsgetrf();
  115. int        lsinsert();
  116. int        lslast();
  117. int        lslock();
  118. int        lsnext();
  119. lseq_t *    lsopen();
  120. int        lsprev();
  121. int        lsputr();
  122. int        lsputrf();
  123. int        lssearch();
  124. int        lssetbuf();
  125. int        lssetcur();
  126. int        lssetvbuf();
  127. int        lssync();
  128. #endif    /* #ifdef AC_PROTO */
  129.  
  130. /* macros */
  131. #define    lscursor(LSP)    ((void *)(                    \
  132.     (LSP)->clspos == NIL ? NULL : ((char *)NULL + 1)        \
  133. ))
  134. #define    lsreccnt(LSP)    ((LSP)->lshdr.reccnt)
  135. #define    lsrecsize(LSP)    ((LSP)->lshdr.recsize)
  136.  
  137. /* lock types */
  138. #define LS_UNLCK    (0)    /* unlock */
  139. #define LS_RDLCK    (1)    /* read lock */
  140. #define LS_WRLCK    (2)    /* write lock */
  141. #define LS_RDLKW    (3)    /* read lock, wait */
  142. #define LS_WRLKW    (4)    /* write lock, wait */
  143.  
  144. /* lseq error codes */
  145. #define LSEOS        (-20)    /* start of lseq error code domain */
  146. #define LSEMFILE    (LSEOS - 1)    /* too many open lseqs */
  147. #define LSECORRUPT    (LSEOS - 2)    /* lseq is corrupt */
  148. #define LSENOPEN    (LSEOS - 3)    /* lseq not open */
  149. #define LSENBUF        (LSEOS - 4)    /* buffering is off */
  150. #define LSELOCK        (LSEOS - 5)    /* incorrect lock type */
  151. #define LSENREC        (LSEOS - 6)    /* no record */
  152. #define LSEBOUND    (LSEOS - 7)    /* record boundary error */
  153. #define LSEEOF        (LSEOS - 8)    /* past end of file */
  154. #define LSEPANIC    (LSEOS - 9)    /* internal lseq error */
  155.  
  156. #endif        /* #ifndef H_LSEQ */
  157.